package com.second.mapper;

import com.second.model.dto.storeInfo.FShopFractionDto;
import com.second.model.pojo.FComment;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import java.util.List;

/**
 * 本接口用来演示:
 *
 * @author: MuTing
 * @createTime: 2022-04-17 14:54
 **/

@Repository //持久层组件标识
public interface FCommentMapper extends JpaRepository<FComment,Integer> {

    List<FComment> findByShopId(Integer id);

    int countByShopId(Integer shopId);

    //自定义DML操作
    @Modifying
    @Query(value = "delete from FComment where id=?1")
    int delByCommentId(Integer id);

    @Query(value = "select new com.second.model.dto.storeInfo.FShopFractionDto(shopId,avg (generalComment),avg (flavor),avg (environment),avg (service)) from FComment where shopId = :shopId")
    FShopFractionDto ScoreCounts(@Param("shopId") Integer shopId);

    //查找评论数量
    int countByUserId(Integer userId);

    //评论分页
    Page<FComment> findByShopId(Integer shopId,Pageable pageable);

    //查询当前用户所有的评论
    List<FComment> findAllByUserIdOrderByCommentTimeDesc(Integer userId);

}
